﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SH.Common.CommonReturn;
using SH.Common.DataDictionary;
using SH.Room.Application.IServices.IRoomNum;
using SH.Room.Domain.RoomClass;
using System.Linq.Expressions;

namespace SH.Room.Read.API.Controllers
{
    /// <summary>
    /// 房号
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class RoomNumController : ControllerBase
    {
        /// <summary>
        /// 房号逻辑层
        /// </summary>
        private readonly IRoomNumServices _roomNumServices;
        /// <summary>
        /// 构造函数注入
        /// </summary>
        /// <param name="roomNumServices"></param>
        public RoomNumController(IRoomNumServices roomNumServices)
        {
            _roomNumServices = roomNumServices;
        }

        /// <summary>
        /// 房号添加
        /// </summary>
        /// <param name="roomNumDto">房号添加DTO</param>
        /// <returns>受影响行数</returns>
        [HttpPost]
        public IActionResult RoomNumAdd(RoomNumDto roomNumDto)
        {
            var result= _roomNumServices.RoomNumAdd(roomNumDto);
            return Ok(result);
        }

        /// <summary>
        /// 房号显示查询分页
        /// </summary>
        /// <param name="rtid">房型名称</param>
        /// <param name="roomNumber">房号名称</param>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">页容量</param>
        /// <returns>受影响行数</returns>
        [HttpGet]
        public IActionResult GetRoomNumList(int rtid=-1, string? roomNumber="", int pageIndex=1, int pageSize=10)
        {
            var res = _roomNumServices.GetRoomNumList(rtid, roomNumber,pageIndex,pageSize);
            return Ok(res);
        }

        /// <summary>
        /// 房号删除
        /// </summary>
        /// <param name="roomId">房号ID</param>
        /// <returns>受影响行数</returns>
        [HttpDelete]
        public IActionResult DeleteRoomNumber(int roomId)
        {
            ApiResult<int> apiResult=new ApiResult<int>();
            var num=_roomNumServices.DeleteRoomNumber(roomId);
            apiResult.Success();
            return Ok(apiResult);
        }

        /// <summary>
        /// 批量删除房号
        /// </summary>
        /// <param name="roomNum">房号实体</param>
        /// <returns>受影响行数</returns>
        [HttpPut]
        public IActionResult BatchDelRoomNum(List<RoomNum> roomNum)
        {
            var result=_roomNumServices.BatchDelRoomNum(roomNum);
            return Ok(result);
        }

        /// <summary>
        /// 字典列表
        /// </summary>
        /// <returns>受影响行数</returns>
        [HttpGet]
        public IActionResult GetDicList(string Identification)
        {
            var res= _roomNumServices.GetDicList(Identification);
            return Ok(res);
        }

        /// <summary>
        /// 房号状态修改
        /// </summary>
        /// <param name="roomid">房号ID</param>
        /// <param name="state">房号状态</param>
        /// <returns>受影响行数</returns>
        [HttpGet]
        public IActionResult UpdState(int roomid, bool state)
        {
            var res=_roomNumServices.UpdState(roomid,state);
            return Ok(res);
        }

        /// <summary>
        /// 房号反填
        /// </summary>
        /// <param name="roomId">房号ID</param>
        /// <returns>受影响行数</returns>
        [HttpGet]
        public IActionResult GetFindRoomNum(int roomId)
        {
            ApiResult<RoomNum> apiResult=new ApiResult<RoomNum>();
            var item = _roomNumServices.GetModelByCondition(x => x.RoomId == roomId);
            apiResult.Success(item);
            return Ok(apiResult);
        }

        /// <summary>
        /// 房号修改
        /// </summary>
        /// <param name="roomNumUpdDto">房号修改DTO</param>
        /// <returns>受影响行数</returns>
        [HttpPost]
        public IActionResult UpdRoomNum(RoomNumUpdDto roomNumUpdDto)
        {
            var res = _roomNumServices.UpdRoomNum(roomNumUpdDto);
            return Ok(res);
        }

        /// <summary>
        /// 调用房号显示
        /// </summary>
        /// <returns>受影响行数</returns>
        [HttpGet]
        public IActionResult IRoomNum()
        {
            var res=_roomNumServices.GetList();
            return Ok(res);
        }


    }
}
